package zerous.dodgestones.core;
import com.badlogic.gdx.graphics.g2d.*;
import com.badlogic.gdx.graphics.*;
import zerous.dodgestones.*;
import zerous.dodgestones.screen.*;
import com.badlogic.gdx.utils.*;
import java.util.*;

public class Stone extends GameObject implements Pool.Poolable
{
	public boolean removeAble = false;
	Sprite body;
	public Stone() {
		
	}
	
	public void init(float speed, float x, float y) {
		double r = Math.random();
		if (r > 0.3) {
			if (Math.random() > 0.5)
				body = new Sprite(Traveler.STONE);
			else 
				body = new Sprite(Traveler.STONE_2);
		} else {
			body = new Sprite(Traveler.STONE2);
		}
		
		body.setSize(body.getWidth()*Info.PIXEL_SIZE, body.getHeight()*Info.PIXEL_SIZE);
		box.setSize(body.getWidth(), body.getHeight());
		
		position.y = y;
		position.x = x;
		velocity.x = -speed;
		removeAble = false;
	}

	@Override
	public void reset() {
		position.setZero();
		velocity.setZero();
		removeAble = true;
	}

	@Override
	public void draw(Batch batch) {
		if (position.x > -box.getWidth()) {
			position.add(velocity);
		
			body.setPosition(position.x, position.y);
			box.setPosition(position.x, position.y);
			body.draw(batch);
		} else {
			removeAble = true;
		}
	}
	
	public void isHitPlayer(Player player) {
		//if(box.contains(player.position.x+player.box.getWidth(), player.position.y) || box.contains(player.position.x + player.box.getWidth(), player.position.y+player.box.getHeight())) {
		//	player.died = true;
		//}
		if (box.contains(player.position.cpy().add(player.box.getWidth()/2, player.box.getHeight()/2))) {
			player.died = true;
		}
	}
}
